import axios from "axios"

const requst = axios.create({
  // baseURL: 'http://183.230.28.133:2023/qr-api',
  baseURL: 'http://www.cqcfsw.com:2023/qr-api',
  // baseURL: 'http://192.168.1.110:8200',
  timeout: 15000
})

// 请求拦截器
requst.interceptors.request.use(
  config => {
    // 在发送请求之前做些什么
    config.headers['Content-Type'] = 'application/json';
    return config;
  },
  error => {
    // 对请求错误做些什么
    return Promise.reject(error);
  }
);

// 响应拦截器
requst.interceptors.response.use(
  response => {
    // 对响应数据做点什么
    return response;
  },
  error => {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);


//上传文件地址

const uploadUrl = requst.defaults.baseURL + '/minio/upload'
export { uploadUrl }

export async function getListTreeById(id: string = '') {

  const params = {
    id
  }

  const result = await requst.get('/menu/listTree', { params })

  return result
}

//获取文件列表
export async function getFileList(pageNum: number, pageSize: number = 15, fileMenu: string) {

  const params = {
    pageNum,
    pageSize,
    fileMenu
  }

  const result = await requst.get('/menu/list', { params })

  return result
}

//添加
export async function addFile(name: string, type: number, fileUrl: string = '', parentId: string = '0') {

  const params = {
    name,
    type,
    fileUrl,
    parentId
  }

  const result = await requst.post('/menu/add', params)

  return result
}

//删除
export async function deleteItem(ids: any[]) {

  const params = {
    ids: ids.join(',')
  }

  const result = await requst.get('/menu/remove', { params })

  return result
}


export async function editItem(id: string, name: string, type: number, fileUrl: string = '') {

  const params = {
    id,
    name,
    type,
    fileUrl,
  }

  const result = await requst.post('/menu/edit', params)

  return result
}

export default requst